<?

if (!$user)
{
  include "page_personal_logon.php";
  return;
}

$PageTitle=$msg["Page_DeleteProfile"];

include "div_menu_personal.php";


if (!$_POST) 
{
  make_form($user);
} 
else 
{
  if (delete_user($user)) 
  {
    $_SESSION["user"] = "";
    print_continue($msg["ProfileDeleted"], "personal");
  }
  else
  {
    echo '<a href="personal">', $msg["Continue"], '</a><br><br>';
  }
};


//-----------------------------------------------------------------------------

function make_form($user) 
{
  global $msg;

?>

<!-- Delete user form -->

<div class="form_area">
<div class="form_div">
<form action="personal_delete_profile" method="post">

  <fieldset class="fields1">

  <dl>
    <?print_user_info($user, True);?>
  </dl>

  <dl class="button_div">
    <button type="submit" name="delete"><?=$msg["Delete"];?></button>
    &nbsp;
    <button type="button" name="cancel" onClick="window.location.href='personal'"><?=$msg["Cancel"];?></button>
  </dl>

  </fieldset>

</form>
</div>
</div>

<?php
};


function delete_user($user) 
{
  global $msg;

  $n = 0;

  try 
  {
    db_call();
    db_delete_user($user["id"]);
  } 
  catch (Exception $e) 
  {
    $errors[$n++] = $e->getMessage();
  }

  if ($n <> 0) 
  {
    print_errors($errors);
    return False;
  }

  return True;
};

?>
